package cn.metafoo.common.exception.utils;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
 * 异常 工具类
 * @author lordgod
 */
public class MetaExceptionUtil {
    /**
     * 获取异常堆栈的字符串
     * @param e 异常
     * @return 堆栈字符串信息
     */
    public static String getExceptionStackTrace(Exception e) {
        ByteArrayOutputStream traceStack = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(traceStack));
        return traceStack.toString();
    }

    /**
     * 获取异常堆栈的字符串
     * @param e 异常
     * @return 堆栈字符串信息
     */
    public static String getStackTrace(Throwable e) {
        ByteArrayOutputStream traceStack = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(traceStack));
        return traceStack.toString();
    }
}
